$(document).ready(function(){
	 init();
	 monitor();
	 service();
})
function init(){

}
function monitor(){

}
function service(){

}

function reg(){
    var mobile=$("input[name='mobile']").val();
    var authCode=$("input[name='authCode']").val();
    var password=$("input[name='password']").val();
    var passwordCheck=$("input[name='passwordCheck']").val();
    if (!$valid.phone(mobile)) {
        return layer.msg("请输入11位合法用户名!");
    }
    if (!$valid.password(password)) {
        return layer.msg("请输入6-32位合法密码!");
    }
    if (!$valid.code(authCode)) {
        return layer.msg("请输入6位合法验证码!");
    }
    if (password!=passwordCheck) {
        return layer.msg("两次输入密码不一致!");
    }
    if(!$('#agree').is(':checked')){
        return layer.msg("请勾选用户协议!");
    }
    var data={
        "mobile":mobile,"password":password,"authCode":authCode
    }
    $.ajax({
        url: ctx+"/passport/save"
        , type: "post"
        , data: data
        , dataType: "json"
        , success: data => {
            if (data.state="ok") {
            	layer.alert("注册成功,3秒后为你跳转至登录界面");
                setTimeout("location.href='/platform'", 3000);
            } else {
                layer.alert(data.msg);
            }
        }
    })
}


function resetPass(){
    var mobile=$("input[name='mobile']").val();
    var authCode=$("input[name='authCode']").val();
    var password=$("input[name='password']").val();
    var passwordCheck=$("input[name='passwordCheck']").val();
    
    if (!$valid.phone(mobile)) {
        return layer.msg("请输入11位合法用户帐号!");
    }
    if (!$valid.password(password)) {
        return layer.msg("请输入6-32位合法密码!");
    }
    if (password!=passwordCheck) {
        return layer.msg("两次输入密码不一致!");
    }
    
    if (!$valid.code(authCode)) {
        return layer.msg("请输入6位合法验证码!");
    }
    
    var data={
        "mobile":mobile,"password":password,"authCode":authCode
    }
    
    
    
    $.ajax({
        url: ctx+"/passport/passwordBack"
        , type: "post"
        , data: data
        , dataType: "json"
        , success: data => {
            if (data.state=="ok") {
                layer.alert("密码重置成功,3秒后为你跳转至登录界面");
                setTimeout("location.href='/platform'", 3000);
            } else {
                layer.alert(data.msg);
            }
        }
    })
}

function sendSms(){
    var mobile=$("input[name='mobile']").val();
    if(!$valid.phone(mobile)){
        return layer.msg("请输入11位合法用户名!");
    }
    
    time($("#authCode"))
    
    
    $.ajax({
        url:ctx+"/passport/sendAuthcode",
        type:"post",
        data:{"mobile":mobile},
        dataType:"json",
        success:function(data){
            if (data.state=="ok"){
//                if (data.code){
//                    $("input[name='authCode']").val(data.code);
//                }
            }else{
            	layer.msg(data.msg);
            }

        }
    })

}



function sendPasswordBackSms(){
    var mobile=$("input[name='mobile']").val();
    if(!$valid.phone(mobile)){
        return layer.msg("请输入11位合法用户名!");
    }
    time($("#authCode"))
    $.ajax({
        url:ctx+"/passport/sendAuthcodeByPasswordBack",
        type:"post",
        data:{"mobile":mobile},
        dataType:"json",
        success:function(data){
            if (data.state=="ok"){
//                if (data.code){
//                    $("input[name='authCode']").val(data.code);
//                }
            }else{
            	layer.msg(data.msg);
            }

        }
    })

}

/**
 * 短信发送倒计时
 * @param o
 * @returns
 */
var wait=60;
function time(o){
    if (wait==0) {
        o.removeAttr("disabled");    
        o.val("输入验证码");
        wait=60;
    }else{
        o.attr("disabled", true);
        o.val(wait+"秒后重新获取");
        wait--;
        setTimeout(function(){
            time(o)
        },1000)
    }
}



